<template>
  <!-- <el-drawer
    v-model="open"
    title="在读学员明细"
    :with-header="true"
    size="85%"
    class="current-student-list-drawer"
    :close-on-click-modal="false"
    :before-close="closeW"
  > -->
  <el-row :gutter="10" class="query-box">
    <el-col :span="22.5"> </el-col>
    <el-col :span="1.5">
      <el-button
        type="plain"
        plain
        icon="Download"
        @click="handleExport(5, '在读学员明细')"
      >
        导出
      </el-button>
    </el-col>
  </el-row>
  <el-table v-loading="tableLoading" :data="list" border>
    <el-table-column label="学员姓名" prop="name" fixed="left" />
    <el-table-column label="手机号" prop="mobile" />
    <el-table-column label="添加日期" prop="addTime" />
    <el-table-column label="学员来源" prop="dictLabel" />
    <el-table-column label="跟进人" prop="counselor" />
    <el-table-column label="当前状态" prop="stage" />
  </el-table>
  <pagination
    v-show="total > 0"
    :total="total"
    v-model:page="queryParams.pageNum"
    v-model:limit="queryParams.pageSize"
    @pagination="getList"
    size="small"
  />
  <!-- </el-drawer> -->
</template>

<script setup>
import {
  dataTrendStudentAPI,
  exportDataTrendAPI,
} from "@/api/dataCenter/registrarData";

const route = useRoute();
let { start, end, type } = route.query;

const { proxy } = getCurrentInstance();
const loading = ref(false);
const tableLoading = ref(false);
const open = ref(false);
const total = ref(0);

const data = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    startDate: start,
    endDate: end,
    type: type,
  },
  list: [],
});

const { queryParams, list } = toRefs(data);

// 导出
function handleExport(type, fileName) {
  let param;
  param = Object.assign({ exportType: type }, queryParams.value);
  param.pageNum = 1;
  param.pageSize = 9999;
  exportDataTrendAPI(param).then((res) => {
    let blob = new Blob([res], {
      type: "application/vnd.ms-excel;charset=utf-8",
    });
    const url = window.URL.createObjectURL(blob),
      link = document.createElement("a");
    link.href = url;
    link.download = fileName + new Date().getTime();
    link.click();
    URL.revokeObjectURL(url); // 释放内存
    proxy.$modal.msgSuccess("导出成功");
  });
}

function getList() {
  loading.value = true;
  dataTrendStudentAPI(queryParams.value).then((response) => {
    list.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

function openW(item) {
  open.value = true;
  //queryParams.value.startDate = item.startDate;
  //queryParams.value.endDate = item.endDate;
  queryParams.value.pageNum = 1;
  getList();
}

openW();

function closeW() {
  open.value = false;
}

defineExpose({ openW }); // 用于父组件调用
</script>

<style lang="scss" scoped></style>
